//
//  MainViewController.m
//  王雷Sinoweibo
//
//  Created by wanglei on 16/10/16.
//  Copyright © 2016年 wanglei. All rights reserved.
//

#import "MainViewController.h"
#import "HomeTableViewController.h"
#import "ProdfileTableViewController.h"
#import "DiscoverTableViewController.h"
#import "MessageTableViewController.h"
#import "MainTabbar.h"
@interface MainViewController ()

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    [MainViewController setUpThemColor];
    
    self.viewControllers = [MainViewController addchildViewControllers];
    self.tabBar.tintColor = [UIColor redColor];
    //    NSLog(@"----%@------",self.tabBar.classForCoder);
    //创建相应的子控制器
    MainTabbar *maintabbar = [[MainTabbar alloc]init];
    [self setValue:maintabbar forKey:@"tabBar"];
    //    NSLog(@"----%@------",self.tabBar.classForCoder);
    SEL selector = NSSelectorFromString(@"plusBtnDidClick");
    [maintabbar.plusBtn addTarget:self action:selector forControlEvents:UIControlEventTouchUpInside];
//    [self plusBtnDidClick:maintabbar.plusBtn];
}


//+ (void)setUpThemColor{}


- (void)userWillLogin{
    
    NSLog(@"userWillLogin");
}

- (void)userWillRegister{
    
    NSLog(@"userWillRegister");
}

- (void)plusBtnDidClick{
    NSLog(@"plusBtnDidClick");
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


+(NSArray *)addchildViewControllers{
    
    HomeTableViewController *hvc = [[HomeTableViewController alloc]init];
    ProdfileTableViewController *pvc = [[ProdfileTableViewController alloc]init];
    DiscoverTableViewController *dvc = [[DiscoverTableViewController alloc]init];
    MessageTableViewController *Mvc = [[MessageTableViewController alloc]init];
    
    [MainViewController mainViewControllerWithRootViewController:hvc title:@"首页" imageName:@"tabbar_home"];
    
    [MainViewController mainViewControllerWithRootViewController:dvc title:@"发现" imageName:@"tabbar_discover"];
    [MainViewController mainViewControllerWithRootViewController:Mvc title:@"消息" imageName:@"tabbar_message_center"];
    [MainViewController mainViewControllerWithRootViewController:pvc title:@"我" imageName:@"tabbar_profile"];
    
    UINavigationController *hvccontroller = [[UINavigationController alloc]initWithRootViewController:hvc];
    
    UINavigationController *pvccontroller = [[UINavigationController alloc]initWithRootViewController:pvc];
    
    UINavigationController *dvccontroller = [[UINavigationController alloc]initWithRootViewController:dvc];
    
    UINavigationController *Mvccontroller = [[UINavigationController alloc]initWithRootViewController:Mvc];
    
    
    return  @[hvccontroller,pvccontroller,dvccontroller,Mvccontroller];
    
}

+(void)mainViewControllerWithRootViewController:(UITableViewController *)ViewController title:(NSString *)title imageName:(NSString *)imageName {
    
    UINavigationController *navcontroller = [[UINavigationController alloc]initWithRootViewController:ViewController];
    
    navcontroller.tabBarItem.badgeValue=@"2";
    ViewController.navigationItem.title = title;
    ViewController.tabBarItem.title = title;
    ViewController.tabBarItem.image = [[UIImage imageNamed:imageName]  imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    ViewController.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted", imageName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    //    切记tintcolor的设定是图标下面的文字的颜色一种简便的做法
    
    //   切记,只有在状态为UIControlStateNormal的时候,字体大小的设定才有启动作用.
    //    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:254.0/255 green:1.0/255 blue:1.0/255 alpha:1.0],NSForegroundColorAttributeName, [UIFont systemFontOfSize:10.0],NSFontAttributeName,nil] forState:UIControlStateSelected];
    //    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithRed:1.0/255 green:254.0/255 blue:1.0/255 alpha:1.0],NSForegroundColorAttributeName, [UIFont systemFontOfSize:20.0],NSFontAttributeName,nil] forState:UIControlStateNormal];
    
}


@end
